﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Nonocast.Scheduling {
	public class TaskImpl<T> : Task<T> {
		public T Context { get; private set; }
		public TaskRule<T> GeneratedBy { get; private set; }
		public DateTime StartTime {
			get { return starttime; }
			set {
				starttime = value;
				Trace.Assert(GeneratedBy != null);
				if (GeneratedBy.ExpirationTime.HasValue) {
					var exp = GeneratedBy.ExpirationTime.Value;
					ExpirationTime = new DateTime(starttime.Year, starttime.Month, starttime.Day, exp.Hour, exp.Minute, exp.Second);
				} else {
					// until 0:00 next day
					ExpirationTime = starttime.Date.AddDays(1);
				}
			}
		}
		public DateTime ExpirationTime { get; private set; }

		public TaskImpl(TaskRule<T> generatedBy) {
			this.GeneratedBy = generatedBy;
			this.Context = generatedBy.Context;
		}

		private DateTime starttime;
	}
}
